﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using NUnit.Framework;
using Rhino.Mocks;

using Chefbook.UserActions;
using Chefbook.ViewModels;

namespace UnitTests.UserActionsTests
{
    [TestFixture]
    public class MoveRecipeActionFixture
    {
        private MockRepository mocks;
        private IUserAction action;
        private CategoryViewModel category1;
        private CategoryViewModel category2;
        private RecipeViewModel recipe;

        [SetUp]
        public void Init()
        {
            mocks = new MockRepository();
            

            category1 = new CategoryViewModel(new Category(null)) { Name = "foo" };
            category2 = new CategoryViewModel(new Category(null)) { Name = "bar" };
            recipe = new RecipeViewModel(new Recipe(category1.CategoryModel)) { Name = "MyRecipe" };


            Assert.Contains(category1, recipe.Categories);
            Assert.Contains(recipe, category1.Recipes);
            Assert.False(recipe.Categories.Contains(category2), "category2.Recipes.Contains(recipe)");
            Assert.False(category2.Recipes.Contains(recipe), "category2.Recipes.Contains(recipe)");
            

            action = new MoveRecipeAction(recipe, category1, category2) ;
        }

        [Test]
        public void DoActionTest()
        {
            action.DoAction();
            Assert.False(recipe.Categories.Contains(category1), "recipe.Categories.Contains(category1)");
            Assert.False(category1.Recipes.Contains(recipe), "category1.Recipes.Contains(recipe)");
            Assert.Contains(category2, recipe.Categories);
            Assert.Contains(recipe, category2.Recipes);

        }

        [Test]
        public void UndoActionTest()
        {
            action.DoAction();
            action.UndoAction();
            Assert.Contains(category1, recipe.Categories);
            Assert.Contains(recipe, category1.Recipes);
            Assert.False(recipe.Categories.Contains(category2), "category2.Recipes.Contains(recipe)");
            Assert.False(category2.Recipes.Contains(recipe), "category2.Recipes.Contains(recipe)");
        }

        [Test]
        public void UndoActionWithoutDoingTest()
        {
            UserActionTestsHelper.UndoActionWithoutDoingTest(action);
        }

        [Test]
        public void UndoActionTwiceAfterDoingTest()
        {
            UserActionTestsHelper.UndoActionTwiceAfterDoingTest(action);
        }

        [Test]
        public void DoActionTwiceTest()
        {
            UserActionTestsHelper.DoActionTwiceTest(action);
        }

        [Test]
        public void ActionNameTest()
        {
            Assert.AreEqual(string.Format("Move Recipe '{0}' from '{1}' to '{2}'", recipe, category1, category2), action.ToString());
        }
    }
}
